﻿var popupStatus = 0;
var inDetail = new String("none");

function loadPopup(name){
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$('#'+name+'Paragraph').fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup(name){
	if(popupStatus==1){
		var str = new String('#'+name+'Paragraph');
		$("#backgroundPopup").fadeOut("slow");
		$("#" + name + "Paragraph").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(name){
	var popupHeight = $('#'+name+'Paragraph').height();
	var popupWidth = $('#'+name+'Paragraph').width();
	var windowHeight = 0;
	var windowScrolled = 0;
	if (typeof window.innerHeight != 'undefined')
	{
		windowHeight = window.innerHeight;
	}
	else if (typeof document.body.innerHeight != 'undefined') {
		windowHeight = document.body.innerHeight;
	}
	else if (typeof document.body.clientHeight != 'undefined') {
		windowHeight = document.body.clientHeight;
	}
	
	if (typeof window.pageYOffset != 'undefined')
	{
		windowScrolled = window.pageYOffset;
	}
	else if (typeof document.body.scrollTop != 'undefined') {
		windowScrolled = document.body.scrollTop;
	}
	else if (typeof document.body.pageYOffset != 'undefined') {
		windowScrolled = document.body.pageYOffset;
	}

	$('#'+name+'Paragraph').css({
		"position": "absolute",
		"top": windowHeight/2 + windowScrolled,
		"left": "50%",
		"margin-top": -popupHeight/2,
		"margin-left": -popupWidth/2
	});
}





function popuper(name){
	inDetail = name.toString();
	centerPopup(name.toString());
	loadPopup(name.toString());
	}
function closer(name){
	disablePopup(name.toString());
	inDetail = new String("none");
}

$(document).keyup(function(e) {
	if (e.keyCode == 27) { 
		if (!(inDetail=="none")){
			closer(inDetail); 
		}
	}  
});